Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve docs, comments, tests, and small refactors #303

Merged
merged 2 commits into from
Sep 20, 2023

Conversation

JimLarson
Copy link

@JimLarson JimLarson commented Aug 24, 2023

Description

Improve the documentation and comments to enable local auditing of all code.

Incidental small refactoring and test expansion.

Test coverage could be improved, but not in this PR.

Author Checklist

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@JimLarson JimLarson added documentation Improvements or additions to documentation agoric-cosmos Agoric tags for cosmos labels Aug 24, 2023
@JimLarson JimLarson self-assigned this Aug 24, 2023
Copy link

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

- `--months`: The number of months to vest over.
- `--time`: The time of day of the vesting event, in 24-hour HH:MM format.
Defaults to midnight.
- `"start_time"`: integer UNIX time;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `"start_time"`: integer UNIX time;
- `"start_time"`: integer seconds since the POSIX epoch;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll stick with "UNIX time" for the concept, since a) it matches the the Go time package API (which doesn't mention an epoch, only "UNIX time"), and b) "UNX time" has its own wikipedia page - "POSIX time" redirects there.

stdout. The following flags control the output:
When the `--write` flag is set, the tool will write a schedule to stdout.
The format is the the format expected by the `create-periodic-vesting-account`
or `create-clawback-vesting-account` cli commands, namely a JSON

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
or `create-clawback-vesting-account` cli commands, namely a JSON
or `create-clawback-vesting-account` cli commands, namely JSON text representing an

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON implies text. However, from all the format-related comments, it could be confusing to have it spread out. I've added a single format section with an example that I hope makes it more clear.

- `--time`: The time of day of the vesting event, in 24-hour HH:MM format.
Defaults to midnight.
- `"start_time"`: integer UNIX time;
- `"periods"`: a JSON array of JSON objects with members:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming there's not another layer of serialization here (e.g., output looks like { …, "periods": [ { "coins": "…", "length_seconds": <digits> }, … ] }).

Suggested change
- `"periods"`: a JSON array of JSON objects with members:
- `"periods"`: an array of objects with members:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct - I've added an example and moved this up to a "format" section, where the JSON context is more clear and I can drop the superfluous and confusing repeats.

Defaults to midnight.
- `"start_time"`: integer UNIX time;
- `"periods"`: a JSON array of JSON objects with members:
- "coins": string giving the text coins format for the amount vested at this event;
Copy link

@gibson042 gibson042 Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think example output would help, especially for this field. Probably just a URL pointing to something that already exists.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a URL for the coins text format. I'll add a multi-denom example.

The following flags control the output:

- `--coins:` The total coins to vest, e.g. `100ubld,50urun`.
- `--months`: The number of monthly to vesting events.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a typo here, but the explanation could still be a little more clear.

Suggested change
- `--months`: The number of monthly to vesting events.
- `--months`: The total number of months to complete vesting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

- `--start`: The vesting start time: i.e. the first event happens in the
next month. Specified in the format `YYYY-MM-DD` or `YYYY-MM-DDThh:mm`,
e.g. `2006-01-02T15:04` for 3:04pm on January 2, 2006.
- `--cliffs`: One or more vesting cliffs in `YYYY-MM-DD` or `YYYY-MM-DDThh:mm`
- `--time`: The time of day of the vesting events, in 24-hour HH:MM format.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--start and --time are interpreted as UTC, right? And does --time override hours and minutes in --start?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. There's a note above that times are interpreted in the local timezone. I added a repeat of that comment here to clarify. The time-of-day of the start time has no bearing on the time-of-day of the later vesting events.

day of the month (or the last day of the month, if the month does not have a
sufficient number of days), for the specified number of months. The total coins
to vest will be divided as evenly as possible among all the vesting events.
Lastly, all events before the last cliff time, if any, are consolidated into a single even

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Lastly, all events before the last cliff time, if any, are consolidated into a single even
Lastly, all events before the last cliff time, if any, are skipped and consolidated into a single event

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "consolidated" is sufficient.

@@ -81,6 +98,7 @@ func divideCoins(coins sdk.Coins, divisor int) ([]sdk.Coins, error) {
// monthlyVestTimes generates timestamps for successive months after startTime.
// The monthly events occur at the given time of day. If the month is not
// long enough for the desired date, the last day of the month is used.
// The number of months must be postive.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, CI caught this typo!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

// readCmd reads periods in JSON from stdin and writes a sequence of vesting
// events in local time to stdout.
// readCmd reads a schedule file from stdin and writes a sequence of vesting
// events in local time to stdout. See README.md for the format.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In local time? Oof. If that's the case we should probably find a way to convey UTC offsets.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it matches the anticipated usage pattern. The comment about timezones in README.md describes how to get other timezones.

@@ -13,6 +13,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/vesting/client/cli"
)

// vestcalc is a utility for creating or reading period files

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vocabulary consistency nit.

Suggested change
// vestcalc is a utility for creating or reading period files
// vestcalc is a utility for creating or reading schedule files

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@JimLarson
Copy link
Author

I've addressed your feedback, @gibson042 , PTAL. I went along with most suggestions, either by letter or spirit. If you feel strongly about any changes I resisted, please re-raise them.

@JimLarson JimLarson merged commit c96af7b into Agoric Sep 20, 2023
30 of 31 checks passed
@JimLarson JimLarson deleted the jimlarson-vestcalc-cleanup branch September 20, 2023 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agoric-cosmos Agoric tags for cosmos C:x/auth documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants